package com.woniuxy.controller;

import com.woniuxy.entity.ShoppingCarts;
import com.woniuxy.service.ShoppingCartsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


/**
 * (ShoppingCarts)表控制层
 *
 * @author makejava
 * @since 2025-07-10 11:54:57
 */
@RestController
@RequestMapping("shoppingCarts")
public class ShoppingCartsController {
    /**
     * 服务对象
     */
    @Autowired
    private ShoppingCartsService shoppingCartsService;
    @GetMapping("/get2")
    public String get(){
        return "ResponseRes";
    }
    /**
     * 分页查询
     *
     * @param shoppingCarts 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<ShoppingCarts>> queryByPage(ShoppingCarts shoppingCarts, PageRequest pageRequest) {
        return ResponseEntity.ok(this.shoppingCartsService.queryByPage(shoppingCarts, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<ShoppingCarts> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.shoppingCartsService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param shoppingCarts 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<ShoppingCarts> add(ShoppingCarts shoppingCarts) {
        return ResponseEntity.ok(this.shoppingCartsService.insert(shoppingCarts));
    }

    /**
     * 编辑数据
     *
     * @param shoppingCarts 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<ShoppingCarts> edit(ShoppingCarts shoppingCarts) {
        return ResponseEntity.ok(this.shoppingCartsService.update(shoppingCarts));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Long id) {
        return ResponseEntity.ok(this.shoppingCartsService.deleteById(id));
    }

}

